package org.rpc.service;

import org.apache.catalina.LifecycleException;
import org.rpc.common.URL;
import org.rpc.protocol.HttpServer;
import org.rpc.register.LocalRegister;
import org.rpc.register.RemoteRegister;
import org.rpc.service.impl.HelloServiceImpl;
import org.rpc.util.EnvironmentUtil;

public class Provider {
    public static void main(String[] args) throws LifecycleException {
        //本地注册helloService
        LocalRegister.register(IHelloService.class.getName(), HelloServiceImpl.class);
        //读取配置文件进行初始化
        EnvironmentUtil.init();
        URL url = new URL("localhost", EnvironmentUtil.getPort(), "1.0");
        //服务中心注册helloService
        RemoteRegister.register(IHelloService.class.getName(), url);
        HttpServer server = new HttpServer();
        //启动服务
        server.start(url.getHostName(), url.getPort(), EnvironmentUtil.getContextPath());
        System.out.println("服务启动成功");
    }
}
